package com.cloud.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;

/**
 * 服务启动日志输出
 *
 * @author yzj
 */
public class RunMainUtils {

    private static Logger logger = LoggerFactory.getLogger(RunMainUtils.class);

    public static void runOuts(ConfigurableApplicationContext context) {
        Environment environment = context.getBean(Environment.class);
        try {
            String ip = InetAddress.getLocalHost().getHostAddress();
            String port = environment.getProperty("server.port");
            logger.info("knife4j文档平台: http://" + ip + ":" + port + "/doc.html" + "\n");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void runMonitor(ConfigurableApplicationContext context) {
        Environment environment = context.getBean(Environment.class);
        try {
            String ip = InetAddress.getLocalHost().getHostAddress();
            String port = environment.getProperty("server.port");
            logger.info("knife4j文档平台: http://" + ip + ":" + port + "/doc.html" + "\n");
            logger.info("微服务监控平台: http://" + ip + ":" + port + "/monitor" + "\n");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void runMagic(ConfigurableApplicationContext context) {
        Environment environment = context.getBean(Environment.class);
        try {
            String ip = InetAddress.getLocalHost().getHostAddress();
            String port = environment.getProperty("server.port");
            logger.info("knife4j文档平台: http://" + ip + ":" + port + "/doc.html" + "\n");
            logger.info("Magic-Api快速开发平台: http://" + ip + ":" + port + "/magic/web/index.html" + "\n");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
